/*********************************************************************
 * Módulo 3. Tutorial de desarrollo con NME. Bucle de juego
 * Programación Multimedia y Juegos
 * Autor: David Vallejo Fernández    david.vallejo@tegnix.com
 * Autor: Carlos González Morcillo   carlos.gonzalez@tegnix.com
 *
 * You can redistribute and/or modify this file under the terms of the
 * GNU General Public License ad published by the Free Software
 * Foundation, either version 3 of the License, or (at your option)
 * and later version. See <http://www.gnu.org/licenses/>.
 *
 * This file is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.  
 *********************************************************************/

package;

import com.eclecticdesignstudio.motion.Actuate;
import flash.events.Event;
import nme.ui.Keyboard;
import nme.events.KeyboardEvent;
import nme.events.MouseEvent;
import flash.Lib;
import nme.display.Bitmap;
import nme.Assets;
import nme.display.StageAlign;
import nme.display.StageScaleMode;

class IntroState extends GameState {

  public static var _instance:IntroState;
  private var _logo:Bitmap;

  private function new () {
    super();  
    _logo = new Bitmap (Assets.getBitmapData ("assets/IntroState.png"));
  }

  // Patrón Singleton.
  public static function getInstance():IntroState {
    if (IntroState._instance == null)
      IntroState._instance = new IntroState();
    return IntroState._instance;
  }

  override function enter() : Void { 
    Lib.current.stage.align = StageAlign.TOP_LEFT;
    Lib.current.stage.scaleMode = StageScaleMode.NO_SCALE;
    // Al entrar añade el logo para que lo renderice.
    addChild(_logo);
  }

  override function exit() : Void { 
    removeChild(_logo);
  }

  
  override function pause() : Void 
  {
  	removeChild(_logo); 
  }
  
  override function resume() : Void 
  {
  	addChild(_logo); 
  }

  override function keyPressed (event:KeyboardEvent) : Void { 
    // Transición al estado de play.
    if (event.keyCode == Keyboard.SPACE) {
      pushState(PlayState.getInstance());
    }
  }

  override function keyReleased (event:KeyboardEvent) : Void { }
  override function mouseClicked (event:MouseEvent) : Void { }
  override function frameStarted (event:Event) : Void { }
  override function frameEnded (event:Event) : Void { }
  
}
